package com.examination.system.administrator.controller;


import com.examination.api.administrator.EmployeeControllerApi;
import com.examination.framework.model.response.QueryResponseResult;
import com.examination.framework.model.response.ResponseResult;
import com.examination.system.administration.Employee;
import com.examination.system.administration.ext.IdentityCardAuthenticationInformation;
import com.examination.system.administration.response.AddAdministrationResult;
import com.examination.system.administration.response.DeleteAdministrationResult;
import com.examination.system.administrator.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.concurrent.Callable;

/**
 * @author 寇淇芮
 * @Date 2019/9/19 16:03
 */
@RestController
@RequestMapping(value = "/administrator/employee")
public class EmployeeController  implements EmployeeControllerApi {
    @Autowired
    EmployeeService employeeService;

    @Override
    @GetMapping("/list/{page}/{size}")
    public Callable<QueryResponseResult<Employee>> findEmployeeList(@PathVariable("page") Integer page,
                          @PathVariable("size") Integer size) {


        return ()->{return employeeService.findEmployeeList(page, size);};
   /*
        Callable<QueryResponseResult<Employee>> callable = new Callable<QueryResponseResult<Employee>>() {
            @Override
            public QueryResponseResult<Employee> call() throws Exception {
                long l = System.currentTimeMillis();

                QueryResponseResult<Employee> employeeList = employeeService.findEmployeeList(page, size);
                System.out.println("服务处理用时:"+(System.currentTimeMillis()-l));
                return employeeList;
            }
        };

        return callable;*/
    }

    @Override
    @PostMapping("/add")
    public AddAdministrationResult addEmployee(@RequestBody Employee employee) throws ParseException {
        return employeeService.addEmployee(employee);
    }

    @Override
    @DeleteMapping("/delect/{employee}")
    public DeleteAdministrationResult deleteEmployeeById(@PathVariable("employee") String employeeId,
                                                         @RequestBody Employee employee) {
        return employeeService.deleteEmployeeById(employeeId,employee);
    }

    @Override
    @PostMapping("/edit/{employeeId}")
    public ResponseResult editEmployeeById(@PathVariable("employeeId") String employeeId,
                                           @RequestBody Employee employee) {
        return employeeService.editEmployeeById(employeeId,employee);
    }

    @Override
    @PostMapping("/check/identityCardVerification/{IDNumber}")
    public IdentityCardAuthenticationInformation identityCardVerificationById(@PathVariable("IDNumber") String IDNumber) {
        return employeeService.identityCardVerificationById(IDNumber);
    }

    @Override
    @PostMapping("/check/telephone/{cellPhoneNumber}")
    public ResponseResult checkCellPhoneNumber(@PathVariable("cellPhoneNumber") String cellPhoneNumber) {
        return employeeService.checkCellPhoneNumber(cellPhoneNumber);
    }


    @Override
    @PostMapping("/update")
    public AddAdministrationResult updateEmployee(@RequestBody Employee employee) {
        return employeeService.updateEmployee(employee);
    }

    @Override
    @GetMapping("/find/{employeeId}")
    public Employee findEmployeeById(@PathVariable("employeeId") String employeeId) {
        return employeeService.findEmployeeById(employeeId);
    }


}
